package com.andy.base.mapper;

import com.andy.base.util.UrlSplitUtil;

public class Engine implements Mapper {

    private Host host;

    public Engine(Host host) {
        this.host = host;
    }

    public Host getHost() {
        return host;
    }

    public void setHost(Host host) {
        this.host = host;
    }

    /**
     * map到需要的对象,然后放入mappingData
     *
     * @param url
     * @param mappingData
     * @return
     * @throws Exception
     */
    @Override
    public Mapper map(String url, MappingData mappingData) throws Exception {
        String hostKey = UrlSplitUtil.getHost(url);

        mappingData.setHost(host);
        mappingData.setHostKey(hostKey);

        return host;
    }

    /**
     * 是否需要继续map
     *
     * @return
     */
    @Override
    public boolean needMapping() {
        return true;
    }
}
